package com.pactera.madp.cp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.prod.ProdGroupEntity;
import com.pactera.madp.cp.handler.CorpContextHolder;
import com.pactera.madp.cp.mapper.prod.ProdGroupMapper;
import com.pactera.madp.cp.service.ProdGroupService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 华融湘江产品分类管理服务实现类
 *
 * @author HuHao
 * @date 2022/3/21 21:31
 */
@Service
public class ProdGroupServiceImpl extends ServiceImpl<ProdGroupMapper, ProdGroupEntity> implements ProdGroupService {

    @Override
    public List<ProdGroupEntity> getProdGroupTree(Integer status) {
        Integer corpId = CorpContextHolder.getCorpId();
        LambdaQueryWrapper<ProdGroupEntity> wrapper = Wrappers.<ProdGroupEntity>lambdaQuery()
                .eq(ProdGroupEntity::getCorpId, corpId)
                .eq(ProdGroupEntity::getParentId, 0);
        if (status != null)
            wrapper.eq(ProdGroupEntity::getStatus, status);
        List<ProdGroupEntity> prodGroupEntities = this.baseMapper.selectList(wrapper);
        return prodGroupEntities;
    }

}
